package com.wang.springbootinit.controller.student;

import com.wang.springbootinit.common.BaseResponse;
import com.wang.springbootinit.common.ErrorCode;
import com.wang.springbootinit.common.ResultUtils;
import com.wang.springbootinit.model.dto.StudentUpdateRequest;
import com.wang.springbootinit.model.vo.StudentVO;
import com.wang.springbootinit.service.StudentService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 学生管理接口
 *
 * @author wang
 */
@RestController
@RequestMapping("/student")
public class StudentController {
    
    @Resource
    private StudentService studentService;

    
    /**
     *
     * @param request
     * @return 学生详细信息
     */
    @GetMapping("/get")
    public BaseResponse<StudentVO> getStudent(HttpServletRequest request) {
        StudentVO student = studentService.getCurrentStudent(request);
        if (student == null) {
            return ResultUtils.error(ErrorCode.NOT_FOUND_ERROR);
        }
        return ResultUtils.success(student);
    }

    /**
     * 更新学生信息
     * @param updateRequest 学生信息更新请求
     * @return 更新结果
     */
    @PostMapping("/update")
    public BaseResponse<Boolean> updateStudent(@RequestBody StudentUpdateRequest updateRequest) {
        return ResultUtils.success(studentService.updateStudent(updateRequest));
    }



} 